<template>
  <EWActiveTaskForm v-if="taskFormValue == 'active'"></EWActiveTaskForm>
  <EWCompleteTaskForm v-if="taskFormValue == 'complete'"></EWCompleteTaskForm>
</template>
<script lang="ts" setup>
import { reactive, onMounted, ref, watch } from 'vue'
import EWActiveTaskForm from '../EWActiveTaskForm/index.vue'
import EWCompleteTaskForm from '../EWCompleteTaskForm/index.vue'
import { apiRequestPost } from '@/api/globalApi.js'
import { useRoute, useRouter } from 'vue-router'
import LocalCache from '@/utils/cache'
// 路由对象
const route = useRoute()
const router = useRouter()
const taskFormValue = ref('active')
const state = reactive({
  // 查询条件
  query: {
    processInstanceId: route.query.processInstanceId,
    taskId: route.query.taskId,
  },
})
const taskForm = ref(null)
const searchFn = () => {
  apiRequestPost('/bpm-service/BpmApi/getTaskUrlForHB', state.query).then((res) => {
    if (res.data.success) {
      taskForm.value = res.data.data
      // setTimeout(() => {
      //   window.close()
      // })
      let url = res.data.data
      const queryParts = url.split('?')
      const queryParams = queryParts.length > 1 ? queryParts[1] : ''

      // 构建新的 URL
      let newUrl = `/portal-vue/EW/EWActiveTaskForm?${queryParams}`
      if (queryParts.length > 1 && queryParts[0] == 'activeTaskForm.vue') {
        newUrl = `/portal-vue/EW/EWActiveTaskForm?${queryParams}`
        taskFormValue.value = 'active'
      } else if (queryParts.length > 1 && queryParts[0] == 'completeTaskForm.vue') {
        newUrl = `/portal-vue/EW/EWCompleteTaskForm?${queryParams}`
        taskFormValue.value = 'complete'
      }
      console.log('EWCompleteTaskForm-------', newUrl)
      // setTimeout(() => {
      //   let tabsList = LocalCache.getCache('tabs')
      //   if (Array.isArray(tabsList.tabsMenuList)) {
      //     tabsList.tabsMenuList = tabsList.tabsMenuList.filter((item) => item.name !== 'EWTaskFormForwarder')
      //   }
      //   LocalCache.setCache('tabs', tabsList)

      //   console.log('tabsList-------12', tabsList)
      // }, 1000)
      // // 执行重定向
      // router.push(newUrl)

      // router.push({LocalCache
      //   name: 'EWActiveTaskForm',
      //   query: state.query,
      // })
    }
  })
}
watch(
  () => route.query,
  (newValue, oldValue) => {
    searchFn()
  }
)
onMounted(() => {
  searchFn()
})
</script>
<style lang="less" scoped></style>
